package com.lmm.yydshtester.command;

import lombok.Data;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * 菜单命令
 * */
@Data
@Service("CommandMenu")
public class CommandMenu implements BaseCommand
{

    public static final String KEY = "0";

    /**
     * 命令展示table栏
     * */
    private String allCommandsShow;
    /**
     * 输入
     * */
    private String commandInput;

    @Override
    public void exec(Scanner scanner)
    {
        System.out.println();
        System.out.println(allCommandsShow);
        System.out.println("please input your order:");
        //  获取第一个指令
        commandInput = scanner.next();
    }


    @Override
    public String getKey()
    {
        return KEY;
    }

    @Override
    public String getTip()
    {
        return "show all commands";
    }


    public void setAllCommand(Map<String, BaseCommand> commandMap)
    {
        Set<Map.Entry<String, BaseCommand>> entrys =
                commandMap.entrySet();
        Iterator<Map.Entry<String, BaseCommand>> iterator =
                entrys.iterator();

        StringBuilder menus = new StringBuilder();
        menus.append("[menu] ");
        while (iterator.hasNext())
        {
            BaseCommand next = iterator.next().getValue();
            menus.append(next.getKey())
                    .append("->")
                    .append(next.getTip())
                    .append(" | ");

        }
        allCommandsShow = menus.toString();
    }
}
